<template>
	<view class="main">
		
		<view class="top-btn" @click="navigateToScan">			
			<u-icon name="scan" color="#222222" size="20"></u-icon>
			<span class="top-btn-name" >扫一扫</span>
		</view>
		<view style="padding: 28upx 0upx;">
			<topSelectNew @onSearch="onSearch"></topSelectNew>
		</view>
		<view class="top-name">领料记录列表</view>
		<view class="list">
			<view class="row row-title">
				<view class="col col-1">识别码</view>
				<view class="col col-2">存货编码</view>
				<view class="col col-3">数量</view>
				<view class="col col-4">批号</view>
				<view class="col col-4">审核状态</view>
				<view class="col col-5">操作</view>
			</view>
			<view class="row row-col" v-for="item in dataList">
				<view class="col col-list col-1 col-1-1">{{item.idcard}}</view>
				<view class="col col-list col-2 col-2-1">{{item.inventoryCode}}</view>
				<view class="col col-list col-3 col-3-1">{{item.quantity}}</view>
				<view class="col col-list col-4 col-4-1" >{{item.batchNumber}}</view>
				<view class="col col-list col-4 col-4-1">{{statusName[item.status]}}</view>
				<view class="col col-list col-5 col-5-1" @click="delLog(item.id)">删除</view>
			</view>
		</view>
		<view class="list-end" v-if="dataList.length">{{endText}}</view>
		
		<u-empty v-if="!dataList.length" mode="car" text="暂无数据" icon="/static/empty-img.png">
		</u-empty>
		
	</view>
</template>


<script>
	import topSelectNew from './topSelect.vue'
	export default {
		components:{topSelectNew},
		data() {
			return {
				statusName:{
					0:'待审核',
					1:'通过',
					2:'不通过'
				},
				total: 0,
				endText: '',
				dataList: [],
				queryParams: {
					pageSize: 10,
					pageNum: 1,
				}
			};
		},
		

		onShow() {
			this.queryParams.pageNum = 1
			this.dataList = []
			this.getList()
		
		},
		methods: {
			onSearch(param){
				this.queryParams.pageNum = 1
				this.dataList = []
				this.queryParams = {...this.queryParams,...param}
				this.getList()				
			},
		
			getList() {
				this.$modal.msgLoading('加载中')
				var that = this			
				this.$postjson('/api/RqReceiveRecord/list', this.queryParams).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						let detail = res.data.rows
		
						if (detail.length < that.queryParams.pageSize) {
							that.endText = '没有更多了'
						}
						that.total = res.data.total
						that.dataList = that.dataList.concat(detail)
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},
			delLog(id){
				let that = this
				this.$modal.confirm('此操作将会删除该记录').then(res=>{
					that.$postjson('/api/RqReceiveRecord/del', {id:id}).then( res => {
						if (res.data.code == 200) {
							that.queryParams.pageNum = 1
							that.dataList = []
							that.getList()
							uni.$u.toast('操作成功')
						} else {
							that.$modal.msgInfo(res.data.msg)
						}					
					})
				})
			},
			navigateToScan() {
				let that = this
				let param = {}
				uni.scanCode({
					success: (res) => {
						param.quantity = that.getUrlParam('quantity',res.result)
						param.batchNumber = that.getUrlParam('batchNumber',res.result)
						param.idcard = that.getUrlParam('idcard',res.result)
						param.inventoryCode = that.getUrlParam('inventoryCode',res.result)
						that.addLog(param)
					},
					fail: (err) => {
						console.error('扫码失败：' + err);
						// 扫码失败后的操作
					}
				});
			},
			getUrlParam(name, url) {
				var query = url.substring(url.indexOf("?") + 1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == name) {
						return pair[1];
					}
				}
				return false;
			},
			
			addLog(param){
				let that = this
				that.$postjson('/api/RqReceiveRecord/add', param).then( res => {
					if (res.data.code == 200) {
						that.queryParams.pageNum = 1
						that.dataList = []
						that.getList()
						uni.$u.toast('操作成功')
					} else {
						that.$modal.msgInfo(res.data.msg)
					}					
				})
			},
			
		},
		onReachBottom: function(e) {
			if (this.total > this.dataList.length) {
				(this.queryParams.pageNum) ++;
				this.getList()
			}
		},

		onPageScroll(e) {},
		onPullDownRefresh() {},

	};
</script>


<style lang="scss" scoped>
	.top-btn{
		width: 170rpx;
		height: 70rpx;
		background: #FFFFFF;
		border-radius: 36rpx;
		display:flex;
		justify-content: center;
		align-items: center;
		// margin-bottom:44upx;
		margin-left:auto;
		.top-btn-nam{
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 28rpx;
			color: #111111;
			margin-left: 14upx;
		}
	}
	.top-name{
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #111111;
		margin-bottom:28upx;
	}
	
	page{
		background: #F9F9F9;
	}
	.main{
		padding:20upx 24upx;
	}
	.list{
		background: #fff;
	}

	.row {
		display: flex;
	}

	.row-title {
		background: #E7F7F0;
		border-radius: 10rpx 10rpx 0rpx 0rpx;
		padding: 18upx 0;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #111111;
	}

	.row-col {
		background: #fff !important;
	
		border-bottom: rgba(235, 236, 241, 1) solid 1upx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #111111;
	}
	.col-list{
		padding: 30upx 0;
	}

	.col {
		text-align: center;
	}

	.col-1 {
		width: 20%;
		// width: 60%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		padding-left:  4upx;
		padding-right:  4upx;
	}

	.col-2 {
		width: 25%;
	}
	
	.col-1-1{border-left:rgba(235, 236, 241,1) solid 1upx;}
	.col-2-1{
		border-right:rgba(235, 236, 241, 1) solid 1upx;
		border-left:rgba(235, 236, 241,1) solid 1upx;
	}

	.col-3 {
		width: 25%;
	}
	.col-3-1{
		border-right:rgba(235, 236, 241, 1) solid 1upx;
	}

	.col-4 {
		width: 30%;
	}
	.col-4-1{border-right:rgba(235, 236, 241, 1) solid 1upx;}
	.col-5 {
		width: 20%;	
	}
	.col-5-1{border-right:rgba(235, 236, 241, 1) solid 1upx;color:#F01022;}
	.list-tip{
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		text-align: center;
		padding: 40upx;
		padding-bottom: 120upx;
	}
</style>